package com.april.pattern.behavioral.observer;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
import java.util.List;

/**
 * @author April
 * @version V1.0.0
 * @date 2019/07/09 11:15
 * @description 被观察者
 */
public class Course {
    private String courseName;

    private List<Question> questionList = new ArrayList<>();

    private PropertyChangeSupport listeners = new PropertyChangeSupport(this);

    public Course(String courseName) {
        this.courseName = courseName;
    }

    public void proposeQuestion(Question question) {
        System.out.println("提交了一个问题");
        questionList.add(question);
        listeners.firePropertyChange(question.getUserName(),
                null, question);
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        listeners.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        listeners.removePropertyChangeListener(listener);
    }
}
